package com.etone.smartAudit.controller;

import com.etone.smartAudit.annotation.LoginAdmin;
import com.etone.smartAudit.domain.Admin;
import com.etone.smartAudit.domain.work.WorkRectifyHistory;
import com.etone.smartAudit.dto.wordOrder.WorkRectifyDTO;
import com.etone.smartAudit.service.WorkOrderPendService;
import com.etone.smartAudit.service.WorkOrderService;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.workOrder.DisposeNumVO;
import com.etone.smartAudit.vo.workOrder.FeedBackVO;
import com.etone.smartAudit.vo.workOrder.ResponseVO;
import com.etone.smartAudit.vo.workOrder.WorkOrderPendVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.List;

/**
 * @author 张任豪
 */
@RestController
@AllArgsConstructor
@Api(tags = "待处理工单", value = "WorkOrderPendController")
public class WorkOrderPendController {

    private WorkOrderPendService workOrderPendService;

    private WorkOrderService workOrderService;

    @ApiOperation(value = "待处理工单列表")
    @GetMapping("/workOrderPend/listPend")
    public PagerVO<WorkOrderPendVO> list(
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "待处理状态（0待派发，1待审核，2待反馈，3待验收，5待整改专项评估）") @RequestParam(required = false, defaultValue = "0") Integer workState,
            @ApiParam(value = "工单状态(0未开始,1进行中,2以办结)") @RequestParam(required = false) Integer status,
            @ApiParam(value = "项目名称") @RequestParam(required = false) String name,
            @ApiParam(value = "整改编号") @RequestParam(required = false) String rectifyCode,
            @ApiParam(value = "开始日期") @RequestParam(required = false) Date startDate,
            @ApiParam(value = "结束日期") @RequestParam(required = false) Date endDate,
            @ApiParam(value = "整改是否超期") @RequestParam(required = false) Integer isOverdue
    ) {
        return workOrderPendService.listPend(page,pageSize,name,rectifyCode,startDate,endDate,isOverdue,admin,workState,status);
    }

    @ApiOperation(value = "批量审核")
    @PostMapping("/workOrderPend/batchAudit/{ids}")
    public FeedBackVO batchAudit(
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam("工单整合id") @PathVariable List<Integer> ids,
            @ApiParam("下一个审核人账号") @RequestParam(required = false) String leadAccount
    ) {
       return workOrderPendService.batchAudit(ids,admin,leadAccount);
    }

    @ApiOperation(value = "批量最终反馈")
    @PostMapping("/workOrderPend/batchFeedBack/{ids}")
    public FeedBackVO batchFeedBack(
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam("工单整合id") @PathVariable List<Integer> ids,
            @ApiParam("部门审核人账号") @RequestParam String deptId
    ) {
        return workOrderPendService.batchFeedBack(ids,deptId,admin);
    }


    @ApiOperation(value = "填写反馈信息")
    @PostMapping("/workOrderPend/writeFeedBack")
    public ResponseVO writeFeedBack(
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam("反馈信息") WorkRectifyDTO workRectifyDTO,
            @ApiParam("部门审核人账号") @RequestParam(value = "deptAuditId",required = false) String deptAuditId
    ) {
        return workOrderPendService.writeFeedBack(workRectifyDTO,deptAuditId,admin);
    }

    @ApiOperation(value = "批量派发工单")
    @PostMapping("/workOrderPend/batchSend/{ids}")
    public ResponseVO batchSend(
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam(value = "派发审核人账号") @RequestParam(value = "auditId") String auditId,
            @ApiParam("工单整合id") @PathVariable List<Integer> ids
    ) {
        return workOrderService.batchSend(auditId,ids,admin);
    }

    @ApiOperation(value = "批量转派")
    @PostMapping("/workOrderPend/transfer/{ids}")
    public ResponseVO transfer(
            @ApiParam("工单整合id") @PathVariable List<Integer> ids,
            @ApiParam(value = "评估负责人账号") @RequestParam("chargeAccount") String chargeAccount
    ) {
        return workOrderPendService.transfer(ids,chargeAccount);
    }

    @ApiOperation(value = "初验通过")
    @PostMapping("/workOrderPend/firstPass/{ids}")
    public void firstPass(
            @ApiParam("工单整合id") @PathVariable List<Integer> ids,
            @ApiParam @LoginAdmin Admin admin
    ) {
        workOrderPendService.firstPass(ids,admin);
    }

    @ApiOperation(value = "复核确定")
    @PostMapping("/workOrderPend/secondCheck")
    public ResponseVO secondCheck(
            @ApiParam(value = "工单Id") @RequestParam(value = "workId") Integer workId,
            @ApiParam(value = "整改评估结果确定") @RequestParam(value = "assessResult",required = false) Integer assessResult,
            @ApiParam(value = "是否启动了责任追究(0未启动,1启动)") @RequestParam(value = "isStartCharge") Integer isStartCharge,
            @ApiParam(value = "问责或责任结果描述") @RequestParam(value = "chargeResult",required = false) String chargeResult,
            @ApiIgnore Admin admin
    ) {
        return workOrderPendService.secondCheck(workId,assessResult,isStartCharge,chargeResult,admin);
    }

    @ApiOperation(value = "批量驳回")
    @PostMapping("/workOrderPend/batchRefusal/{ids}")
    public void batchRefusal(
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam(value = "工单整合id") @PathVariable List<Integer> ids,
            @ApiParam(value = "驳回原因") @RequestParam("refusalMsg") String refusalMsg
    ) {
        workOrderPendService.batchRefusal(ids,refusalMsg,admin);
    }

    @ApiOperation(value = "批量办结")
    @PostMapping("/workOrderPend/batchFinish/{ids}")
    public void batchFinish(
            @ApiParam(value = "工单整合id") @PathVariable List<Integer> ids,
            @ApiIgnore Admin admin
    ) {
        workOrderPendService.batchFinish(ids,admin);
    }

    @ApiOperation(value = "判断是否当前登录对象是否为责任人")
    @PostMapping("/workOrderPend/isChargeMan/{ids}")
    public ResponseVO<Boolean> isChargeMan(
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam(value = "工单整合id") @PathVariable List<Integer> ids
    ) {
        return workOrderPendService.isChargeMan(ids,admin);
    }

    @ApiOperation(value = "获取反馈编辑历史")
    @GetMapping("/workOrderPend/getRectifyHistory")
    public PagerVO<WorkRectifyHistory> getRectifyHistory(
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "工单id") @RequestParam("workId") Integer workId
    ) {
        return workOrderPendService.getRectifyHistory(page,pageSize,workId);
    }

    @ApiOperation(value = "待处理工单条数")
    @GetMapping("/workOrderPend/getDisposeNum")
    public DisposeNumVO getDisposeNum(@ApiIgnore @LoginAdmin Admin admin) {
        return workOrderPendService.getDisposeNum(admin);
    }
}
